<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>wiiconnect</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="while.html" title="while" />
    <link rel="next" href="wiidata.html" title="wiidata" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">wiiconnect</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="while.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="wiidata.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="wiiconnect"></a>
      <div class="titlepage"></div>
      <a id="Indexwiiconnect" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">wiiconnect</span>
        </h2>
        <p>wiiconnect — 
      Reads data from a number of external Nintendo Wiimote controllers.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168251168"></a>
        <h2>Description</h2>
        <p>
      Opens and at control-rate polls up to four external Nintendo Wiimote controllers.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168315168"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ires <span class="command"><strong>wiiconnect</strong></span> [itimeout, imaxnum]</pre>
      </div>
      <div class="refsect1">
        <a id="idp168317376"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>itimeout</em></span> -- integer number of seconds the
      system should wait for all Wiimotes to be connected.  If not
      given it defaults to 10 seconds.
    </p>
        <p>
      <span class="emphasis"><em>imaxnum</em></span> -- maximum number of Wiimotes to locate.  If not
      given it defaults to 4.
    </p>
        <p>
      Initially each Wiimote has its numeric allocation indicated by
      lighting one of the four LEDs.
    </p>
        <p>
      <span class="emphasis"><em>ires</em></span> -- return value is 1 if sucess or zero
      on failure.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168321344"></a>
        <h2>Performance</h2>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
       Please note that these opcodes are currently only supported on
       Linux.
     </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
      Every control cycle each Wiimote is polled for its status and
      position.  These values are read by
      the <span class="emphasis"><em>wiidata</em></span> opcode.  The result returned is
      1 in most cases, but will be zero if a Wiimote disconnects,
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168324080"></a>
        <h2>Example</h2>
        <p>
      Here is an example of the wii opcodes. It uses the file <a class="ulink" href="examples/wii.csd" target="_top"><em class="citetitle">wii.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp168325936"></a>
          <p class="title">
            <strong>Example 1049. Example of the wii opcodes.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-+rtaudio=alsa -o dac:hw:0
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">ksmps</span> <span class="op">=</span> 400

<span class="omacro">#define</span> WII_B           #3#
<span class="omacro">#define</span> WII_A           #4#
<span class="omacro">#define</span> WII_R_A         #304#
<span class="omacro">#define</span> WII_PITCH       #20#
<span class="omacro">#define</span> WII_ROLL        #21#
<span class="omacro">#define</span> WII_BATTERY     #27#

<span class="omacro">#define</span> WII_RUMBLE      #3#
<span class="omacro">#define</span> WII_SET_LEDS    #4#

gkcnt <span class="opc">init</span> 1

<span class="oblock">instr</span> 1  
  i1  wiiconnect 3,1

      wiirange   $WII_PITCH., <span class="op">-</span>20, 0
  kb  wiidata    $WII_BATTERY.
  kt  wiidata    $WII_B.
  ka  wiidata    $WII_A.
  kra wiidata    $WII_R_A.
  gka wiidata    $WII_PITCH.
  gkp wiidata    $WII_ROLL.
<span class="comment">; If the B (trigger) button is pressed then activate a note</span>
  <span class="octrl">if</span>  (kt<span class="op">==</span>0)    <span class="octrl">goto</span> <span class="olabel">ee</span>
  <span class="opc">event</span> "i", 2, 0, 5
  gkcnt <span class="op">=</span> gkcnt <span class="op">+</span> 1
  wiisend       $WII_SET_LEDS., gkcnt
<span class="olabel">ee</span><span class="op">:</span>
  <span class="octrl">if</span> (ka<span class="op">==</span>0)    <span class="octrl">goto</span> <span class="olabel">ff</span>
  wiisend       $WII_RUMBLE., 1
<span class="olabel">ff</span><span class="op">:</span>
  <span class="octrl">if</span> (kra<span class="op">==</span>0)   <span class="octrl">goto</span> <span class="olabel">gg</span>
  wiisend       $WII_RUMBLE., 0
<span class="olabel">gg</span><span class="op">:</span>
  <span class="opc">printk2</span>  kb
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2
  a1 <span class="opc">oscil</span>  <span class="opc">ampdbfs</span>(gka), 440<span class="op">+</span>gkp, 1
     <span class="opc">outs</span>   a1, a1
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1 0 4096 10 1
<span class="stamnt">i</span>1 0 300

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168330224"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="wiidata.html" title="wiidata"><em class="citetitle">wiidata</em></a>,
      <a class="link" href="wiirange.html" title="wiirange"><em class="citetitle">wiirange</em></a>,
      <a class="link" href="wiisend.html" title="wiisend"><em class="citetitle">wiisend</em></a>
     </p>
      </div>
      <div class="refsect1">
        <a id="idp168334192"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch</td>
          </tr>
          <tr>
            <td>Codemist Ltd</td>
          </tr>
          <tr>
            <td>2009</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 5.11</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="while.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="wiidata.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">while </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> wiidata</td>
        </tr>
      </table>
    </div>
  </body>
</html>
